# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time      :2022/8/5 0005 0:22
# @Author    :jiaxuesong
'''
导包

定义读取配置文件类
    定义初始化函数，
        获取配置文件路径
        打开配置文件

    定义对外方法
        获取配置文件内容
'''

import os, time
from configparser import ConfigParser

class ReadConfig(object):

    def __init__(self):
        self.conf_file = os.path.dirname(os.path.dirname(__file__)) + r'/config.ini'
        self.conf = ConfigParser()
        self.conf.read(self.conf_file, encoding='UTF-8')

    def read_conf(self, section, option = 'all'):
        if option == 'all':
            return self.conf.items(section)
        else:
            return self.conf.get(section, option)

if __name__ == '__main__':
    re = ReadConfig()
    print(re.read_conf('mysql', 'host'))
